package com.zbs.framework.common.mybatis;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
import org.apache.ibatis.executor.keygen.KeyGenerator;

public class ColumnCodeMp {

    public static void keyGenerator(TableInfo tableInfo, KeyGenerator keyGenerator, String keyProperty, String keyColumn, String baseStatementId, MapperBuilderAssistant builderAssistant) {
        if (tableInfo.getIdType() == IdType.AUTO) {
            keyGenerator = Jdbc3KeyGenerator.INSTANCE;
            keyProperty = tableInfo.getKeyProperty();
            keyColumn = tableInfo.getKeyColumn();
        } else if (null != tableInfo.getKeySequence()) {
            keyGenerator = TableInfoHelper.genKeyGenerator(baseStatementId, tableInfo, builderAssistant);
            keyProperty = tableInfo.getKeyProperty();
            keyColumn = tableInfo.getKeyColumn();
        }
    }
}
